//
//  BGMessageImageView.m
//  bigMall
//
//  Created by LTOVE on 16/7/25.
//  Copyright © 2016年 thinklev. All rights reserved.
//

#import "BGMessageImageView.h"
#import "UIImageView+WebCache.h"
@implementation BGMessageImageView

+ (UIView *)initWithFrame:(CGRect)frame andDataArray:(NSArray *)dataArray
{
    BGMessageImageView *view = [[BGMessageImageView alloc]initWithFrame:frame];
    GWLog(@"%f",view.height);
    //使用九宫格动态创建视图
    [view setUpImageViewWith:view andDataArray:dataArray];
    view.backgroundColor = [UIColor whiteColor];
    return view;
}

- (void)setUpImageViewWith:(UIView *)view andDataArray:(NSArray *)dataArray
{
    
    int colCount = 3;
    CGFloat width = (view.width - 20 * (colCount + 1)) / (CGFloat)colCount;
    CGFloat heigh = width * 1.17;
    CGFloat maginX = (view.width - colCount * width - 20)/(colCount + 1);
    CGFloat maginY = BGMagListMaginY;
    for (int i = 0 ; i < dataArray.count; i ++) {
        int row = i / colCount;
        int col = i % colCount;
        CGFloat x = maginX  + col * (width + maginX);
        CGFloat y = maginY + row * (heigh + maginY);
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(x, y, width, heigh)];
        NSString *UrlStr = dataArray[i];
//        [imageView sd_setImageWithURL:[NSURL URLWithString:UrlStr]];
        [imageView sd_setImageWithURL:[NSURL URLWithString:UrlStr] placeholderImage:[UIImage imageNamed:nil]];
        
        [view addSubview:imageView];
        
    }
}
@end
